<template>
  <div class="app-container">

    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="1px" label-position="left">
      <el-col :span="100">
        <el-form-item label="状态" prop="suppliesUseFlag" size="mini" label-width="40px">
          <el-select v-model="queryParams.suppliesUseFlag" placeholder="是否启用" clearable :style="{width: '100%'}" >
            <el-option
              v-for="dict in dict.type.service_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            />
          </el-select>
        </el-form-item>

        <el-form-item label="" prop="suppliesName" size="mini" label-width="0px">
          <el-input
            v-model="queryParams.suppliesName"
            placeholder="请输入耗材名称"
            clearable
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
      </el-col>
      <!--<el-form-item label="耗材代码" prop="suppliesCode">-->
      <!--  <el-input-->
      <!--    v-model="queryParams.suppliesCode"-->
      <!--    placeholder="请输入耗材代码"-->
      <!--    clearable-->
      <!--    @keyup.enter.native="handleQuery"-->
      <!--  />-->
      <!--</el-form-item>-->
      <!--<el-form-item label="耗材单位" prop="suppliesPerunit">-->
      <!--  <el-input-->
      <!--    v-model="queryParams.suppliesPerunit"-->
      <!--    placeholder="请输入耗材单位"-->
      <!--    clearable-->
      <!--    @keyup.enter.native="handleQuery"-->
      <!--  />-->
      <!--</el-form-item>-->
      <!--<el-form-item label="耗材价格" prop="suppliesPrice">-->
      <!--  <el-input-->
      <!--    v-model="queryParams.suppliesPrice"-->
      <!--    placeholder="请输入耗材价格"-->
      <!--    clearable-->
      <!--    @keyup.enter.native="handleQuery"-->
      <!--  />-->
      <!--</el-form-item>-->
      <!--<el-form-item label="开始日期">-->
      <!--  <el-date-picker-->
      <!--    v-model="daterangeSuppliesStartdate"-->
      <!--    style="width: 240px"-->
      <!--    value-format="yyyy-MM-dd"-->
      <!--    type="daterange"-->
      <!--    range-separator="-"-->
      <!--    start-placeholder="开始日期"-->
      <!--    end-placeholder="结束日期"-->
      <!--  ></el-date-picker>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="结束日期">-->
      <!--  <el-date-picker-->
      <!--    v-model="daterangeSuppliesEnddate"-->
      <!--    style="width: 240px"-->
      <!--    value-format="yyyy-MM-dd"-->
      <!--    type="daterange"-->
      <!--    range-separator="-"-->
      <!--    start-placeholder="开始日期"-->
      <!--    end-placeholder="结束日期"-->
      <!--  ></el-date-picker>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="创建者" prop="suppliesCreateBy">-->
      <!--  <el-input-->
      <!--    v-model="queryParams.suppliesCreateBy"-->
      <!--    placeholder="请输入创建者"-->
      <!--    clearable-->
      <!--    @keyup.enter.native="handleQuery"-->
      <!--  />-->
      <!--</el-form-item>-->
      <!--<el-form-item label="创建时间">-->
      <!--  <el-date-picker-->
      <!--    v-model="daterangeSuppliesCreateTime"-->
      <!--    style="width: 240px"-->
      <!--    value-format="yyyy-MM-dd"-->
      <!--    type="daterange"-->
      <!--    range-separator="-"-->
      <!--    start-placeholder="开始日期"-->
      <!--    end-placeholder="结束日期"-->
      <!--  ></el-date-picker>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="更新者" prop="suppliesUpdateBy">-->
      <!--  <el-input-->
      <!--    v-model="queryParams.suppliesUpdateBy"-->
      <!--    placeholder="请输入更新者"-->
      <!--    clearable-->
      <!--    @keyup.enter.native="handleQuery"-->
      <!--  />-->
      <!--</el-form-item>-->
      <!--<el-form-item label="更新时间">-->
      <!--  <el-date-picker-->
      <!--    v-model="daterangeSuppliesUpdateTime"-->
      <!--    style="width: 240px"-->
      <!--    value-format="yyyy-MM-dd"-->
      <!--    type="daterange"-->
      <!--    range-separator="-"-->
      <!--    start-placeholder="开始日期"-->
      <!--    end-placeholder="结束日期"-->
      <!--  ></el-date-picker>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="删除标志" prop="suppliesDelFlag">-->
      <!--  <el-select v-model="queryParams.suppliesDelFlag" placeholder="请选择删除标志" clearable>-->
      <!--    <el-option-->
      <!--      v-for="dict in dict.type.service_yes_no"-->
      <!--      :key="dict.value"-->
      <!--      :label="dict.label"-->
      <!--      :value="dict.value"-->
      <!--    />-->
      <!--  </el-select>-->
      <!--</el-form-item>-->
      <!--<el-form-item label="耗材描述" prop="suppliesDescription">-->
      <!--  <el-input-->
      <!--    v-model="queryParams.suppliesDescription"-->
      <!--    placeholder="请输入耗材描述"-->
      <!--    clearable-->
      <!--    @keyup.enter.native="handleQuery"-->
      <!--  />-->
      <!--</el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <!--<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['service:supplies:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['service:supplies:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['service:supplies:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['service:supplies:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="suppliesList" @selection-change="handleSelectionChange" >
      <el-table-column type="selection" width="50" align="center" />
      <!--<el-table-column label="耗材ID" align="center" prop="suppliesId" />-->
      <el-table-column label="耗材代码" align="left" prop="suppliesCode" width="90"/>
      <el-table-column label="耗材名称" align="left" prop="suppliesName" width="290"/>
      <el-table-column label="单位" align="left" prop="suppliesPerunit" width="50"/>
      <el-table-column label="单价" align="left" prop="suppliesPrice" width="50"/>
      <!--<el-table-column label="开始日期" align="center" prop="suppliesStartdate" width="180">-->
      <!--  <template slot-scope="scope">-->
      <!--    <span>{{ parseTime(scope.row.suppliesStartdate, '{y}-{m}-{d}') }}</span>-->
      <!--  </template>-->
      <!--</el-table-column>-->
      <!--<el-table-column label="结束日期" align="center" prop="suppliesEnddate" width="180">-->
      <!--  <template slot-scope="scope">-->
      <!--    <span>{{ parseTime(scope.row.suppliesEnddate, '{y}-{m}-{d}') }}</span>-->
      <!--  </template>-->
      <!--</el-table-column>-->
      <!--<el-table-column label="创建者" align="center" prop="suppliesCreateBy" />-->
      <!--<el-table-column label="创建时间" align="center" prop="suppliesCreateTime" width="180">-->
      <!--  <template slot-scope="scope">-->
      <!--    <span>{{ parseTime(scope.row.suppliesCreateTime, '{y}-{m}-{d}') }}</span>-->
      <!--  </template>-->
      <!--</el-table-column>-->
      <!--<el-table-column label="更新者" align="center" prop="suppliesUpdateBy" />-->
      <!--<el-table-column label="更新时间" align="center" prop="suppliesUpdateTime" width="180">-->
      <!--  <template slot-scope="scope">-->
      <!--    <span>{{ parseTime(scope.row.suppliesUpdateTime, '{y}-{m}-{d}') }}</span>-->
      <!--  </template>-->
      <!--</el-table-column>-->
      <el-table-column label="状态" align="center" prop="suppliesUseFlag" width="70">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.service_yes_no" :value="scope.row.suppliesUseFlag"/>
        </template>
      </el-table-column>
      <!--<el-table-column label="特需项目标识" align="center" prop="suppliesNeedFlag" />-->
      <!--<el-table-column label="特殊项目标识" align="center" prop="suppliesDifferentFlag" />-->
      <!--<el-table-column label="删除标志" align="center" prop="suppliesDelFlag">-->
      <!--  <template slot-scope="scope">-->
      <!--    <dict-tag :options="dict.type.service_yes_no" :value="scope.row.suppliesDelFlag"/>-->
      <!--  </template>-->
      <!--</el-table-column>-->
      <!--<el-table-column label="备注" align="center" prop="suppliesRemark" />-->
      <!--<el-table-column label="耗材图片" align="center" prop="suppliesPicture" width="100">-->
      <!--  <template slot-scope="scope">-->
      <!--    <image-preview :src="scope.row.suppliesPicture" :width="50" :height="50"/>-->
      <!--  </template>-->
      <!--</el-table-column>-->
      <!--<el-table-column label="耗材描述" align="center" prop="suppliesDescription" />-->
      <!--<el-table-column label="操作" align="center" class-name="small-padding fixed-width">-->
      <!--  <template slot-scope="scope">-->
      <!--    <el-button-->
      <!--      size="mini"-->
      <!--      type="text"-->
      <!--      icon="el-icon-edit"-->
      <!--      @click="handleUpdate(scope.row)"-->
      <!--      v-hasPermi="['service:supplies:edit']"-->
      <!--    >修改</el-button>-->
      <!--    <el-button-->
      <!--      size="mini"-->
      <!--      type="text"-->
      <!--      icon="el-icon-delete"-->
      <!--      @click="handleDelete(scope.row)"-->
      <!--      v-hasPermi="['service:supplies:remove']"-->
      <!--    >删除</el-button>-->
      <!--  </template>-->
      <!--</el-table-column>-->
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"

    />

    <!-- 添加或修改耗材表对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1000px" append-to-body >
      <p><b>耗材项目</b></p>
      <el-form ref="form" :model="form" :rules="rules" label-width="90px" :inline="true">
        <el-form-item label="耗材代码" prop="suppliesCode">
          <el-input v-model="form.suppliesCode" placeholder="请输入耗材代码" />
        </el-form-item>
        <el-form-item label="耗材名称" prop="suppliesName">
          <el-input v-model="form.suppliesName" :width="400" placeholder="请输入耗材名称" />
        </el-form-item>
        <!--<el-form-item label="耗材价格" prop="suppliesPrice">-->
        <!--  <el-input v-model="form.suppliesPrice" placeholder="请输入耗材价格" />-->
        <!--</el-form-item>-->
        <el-form-item label="开始日期" prop="suppliesStartdate">
          <el-date-picker clearable
            v-model="form.suppliesStartdate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择开始日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结束日期" prop="suppliesEnddate">
          <el-date-picker clearable
            v-model="form.suppliesEnddate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="单位" prop="suppliesPerunit">
          <el-input v-model="form.suppliesPerunit" placeholder="请输入耗材单位" />
        </el-form-item>
        <!--<el-form-item label="创建者" prop="suppliesCreateBy">-->
        <!--  <el-input v-model="form.suppliesCreateBy" placeholder="请输入创建者" />-->
        <!--</el-form-item>-->
        <!--<el-form-item label="创建时间" prop="suppliesCreateTime">-->
        <!--  <el-date-picker clearable-->
        <!--    v-model="form.suppliesCreateTime"-->
        <!--    type="date"-->
        <!--    value-format="yyyy-MM-dd"-->
        <!--    placeholder="请选择创建时间">-->
        <!--  </el-date-picker>-->
        <!--</el-form-item>-->
        <!--<el-form-item label="更新者" prop="suppliesUpdateBy">-->
        <!--  <el-input v-model="form.suppliesUpdateBy" placeholder="请输入更新者" />-->
        <!--</el-form-item>-->
        <!--<el-form-item label="更新时间" prop="suppliesUpdateTime">-->
        <!--  <el-date-picker clearable-->
        <!--    v-model="form.suppliesUpdateTime"-->
        <!--    type="date"-->
        <!--    value-format="yyyy-MM-dd"-->
        <!--    placeholder="请选择更新时间">-->
        <!--  </el-date-picker>-->
        <!--</el-form-item>-->
        <el-form-item label="有效标志" prop="suppliesUseFlag">
          <el-select v-model="form.suppliesUseFlag" placeholder="请选择有效标志">
            <el-option
              v-for="dict in dict.type.service_yes_no"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <!--<el-form-item label="删除标志" prop="suppliesDelFlag">-->
        <!--  <el-select v-model="form.suppliesDelFlag" placeholder="请选择删除标志">-->
        <!--    <el-option-->
        <!--      v-for="dict in dict.type.service_yes_no"-->
        <!--      :key="dict.value"-->
        <!--      :label="dict.label"-->
        <!--      :value="dict.value"-->
        <!--    ></el-option>-->
        <!--  </el-select>-->
        <!--</el-form-item>-->
        <el-form-item label="耗材描述" prop="suppliesDescription">
          <el-input v-model="form.suppliesDescription" placeholder="请输入耗材描述" />
        </el-form-item>
        <el-form-item label="备注" prop="suppliesRemark">
          <el-input v-model="form.suppliesRemark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="耗材图片" prop="suppliesPicture">
          <image-upload v-model="form.suppliesPicture"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listSupplies, getSupplies, delSupplies, addSupplies, updateSupplies } from "@/api/service/supplies";

export default {
  name: "Supplies",
  dicts: ['service_yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 耗材表表格数据
      suppliesList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 耗材描述时间范围
      daterangeSuppliesStartdate: [],
      // 耗材描述时间范围
      daterangeSuppliesEnddate: [],
      // 耗材描述时间范围
      daterangeSuppliesCreateTime: [],
      // 耗材描述时间范围
      daterangeSuppliesUpdateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        suppliesCode: null,
        suppliesName: null,
        suppliesPerunit: null,
        suppliesPrice: null,
        suppliesStartdate: null,
        suppliesEnddate: null,
        suppliesCreateBy: null,
        suppliesCreateTime: null,
        suppliesUpdateBy: null,
        suppliesUpdateTime: null,
        suppliesUseFlag: null,
        suppliesNeedFlag: null,
        suppliesDifferentFlag: null,
        suppliesDelFlag: null,
        suppliesRemark: null,
        suppliesPicture: null,
        suppliesDescription: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询耗材表列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeSuppliesStartdate && '' != this.daterangeSuppliesStartdate) {
        this.queryParams.params["beginSuppliesStartdate"] = this.daterangeSuppliesStartdate[0];
        this.queryParams.params["endSuppliesStartdate"] = this.daterangeSuppliesStartdate[1];
      }
      if (null != this.daterangeSuppliesEnddate && '' != this.daterangeSuppliesEnddate) {
        this.queryParams.params["beginSuppliesEnddate"] = this.daterangeSuppliesEnddate[0];
        this.queryParams.params["endSuppliesEnddate"] = this.daterangeSuppliesEnddate[1];
      }
      if (null != this.daterangeSuppliesCreateTime && '' != this.daterangeSuppliesCreateTime) {
        this.queryParams.params["beginSuppliesCreateTime"] = this.daterangeSuppliesCreateTime[0];
        this.queryParams.params["endSuppliesCreateTime"] = this.daterangeSuppliesCreateTime[1];
      }
      if (null != this.daterangeSuppliesUpdateTime && '' != this.daterangeSuppliesUpdateTime) {
        this.queryParams.params["beginSuppliesUpdateTime"] = this.daterangeSuppliesUpdateTime[0];
        this.queryParams.params["endSuppliesUpdateTime"] = this.daterangeSuppliesUpdateTime[1];
      }
      listSupplies(this.queryParams).then(response => {
        this.suppliesList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        suppliesId: null,
        suppliesCode: null,
        suppliesName: null,
        suppliesPerunit: null,
        suppliesPrice: null,
        suppliesStartdate: null,
        suppliesEnddate: null,
        suppliesCreateBy: null,
        suppliesCreateTime: null,
        suppliesUpdateBy: null,
        suppliesUpdateTime: null,
        suppliesUseFlag: null,
        suppliesNeedFlag: null,
        suppliesDifferentFlag: null,
        suppliesDelFlag: null,
        suppliesRemark: null,
        suppliesPicture: null,
        suppliesDescription: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeSuppliesStartdate = [];
      this.daterangeSuppliesEnddate = [];
      this.daterangeSuppliesCreateTime = [];
      this.daterangeSuppliesUpdateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.suppliesId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "耗材维护";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const suppliesId = row.suppliesId || this.ids
      getSupplies(suppliesId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "耗材维护";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.suppliesId != null) {
            updateSupplies(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addSupplies(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const suppliesIds = row.suppliesId || this.ids;
      this.$modal.confirm('是否确认删除耗材表编号为"' + suppliesIds + '"的数据项？').then(function() {
        return delSupplies(suppliesIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('service/supplies/export', {
        ...this.queryParams
      }, `supplies_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
